<?php

namespace AdminBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Doctrine\ORM\EntityRepository;
use AdminBundle\Utility\Constant;

class TaskQueueWaitingType extends AbstractType
{
    /**
     * {@inheritdoc}
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('templateId', EntityType::class, [
            'label' => '模版',
            'label_attr' => Constant::LABEL_ATTR_DEFAULT,
            'attr' => [
                'placeholder' => '请选择终模版',
                'class' => "chosen-select form-control"],
            'required' => true,
            'empty_data' => "",
            // input=choice|select , must be require
            'em' => 'default',
            'class' => 'AdminBundle:TaskTemplate',
            'query_builder' => function (EntityRepository $repo) {
                return $repo->createQueryBuilder('u')->where('u.isEnabled=1')->orderBy('u.id', 'desc');
            },
            'choice_label' => function ($baseDataSource) {
                return $baseDataSource->getName() . '--' . $baseDataSource->getNote();
            },
            'choice_value' => 'id',
            'choice_name' => 'id',
            'expanded' => false,
            'multiple' => false,
        ])->add('deviceGroupId', EntityType::class, [
            'label' => '终端组',
            'label_attr' => Constant::LABEL_ATTR_DEFAULT,
            'attr' => [
                'placeholder' => '请选择终端组',
                'class' => "chosen-select form-control"],
            'required' => true,
            'empty_data' => "",
            // input=choice|select , must be require
            'em' => 'default',
            'class' => 'AdminBundle:BaseGroup',
            'query_builder' => function (EntityRepository $repo) {
                return $repo->createQueryBuilder('u')->where('u.isEnabled=1')->orderBy('u.id', 'desc');
            },
            'choice_label' => function ($baseDataSource) {
                return $baseDataSource->getName() . '--' . $baseDataSource->getNote();
            },
            'choice_value' => 'id',
            'choice_name' => 'id',
            'expanded' => false,
            'multiple' => false,
        ])->add('deviceId', ChoiceType::class, [
            'label' => '终端',
            'label_attr' => Constant::LABEL_ATTR_DEFAULT,
            'attr' => [
                'placeholder' => '终端',
//                'class' => "chosen-select form-control"
                'class' => "form-control"
            ],
            'required' => false,

            'empty_data' => '',
            'expanded' => false,
            'multiple' => false,
        ])->add('webchatUsername', ChoiceType::class, [
            'label' => '微信号',
            'label_attr' => Constant::LABEL_ATTR_DEFAULT,
            'attr' => [
                'placeholder' => '请输入微信号',
                'class' => "form-control"
//                'class' => "chosen-select form-control"
            ],
            'required' => false,

            'empty_data' => '',
            'expanded' => false,
            'multiple' => false,
        ]);
//        $builder->add('name')->add('note')->add('creator')->add('ip')->add('ctime')->add('uri')->add('method')->add('action')->add('params')->add('deviceImei')->add('deviceGroupId')->add('webchatUsername');
    }

    /**
     * {@inheritdoc}
     */
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'AdminBundle\Entity\TaskQueueWaiting'
        ));
    }

    /**
     * {@inheritdoc}
     */
    public function getBlockPrefix()
    {
        return 'adminbundle_taskqueuewaiting';
    }


}
